<template> <div class="app-container">
 轮播图列表
    <!--查询表单-->
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="bannerQueryJson.title" placeholder="轮播图名称"/>
      </el-form-item>

      <el-form-item label="添加时间">
        <el-date-picker
          v-model="bannerQueryJson.begin"
          type="datetime"
          placeholder="选择开始时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          default-time="00:00:00"
        />
      </el-form-item>
      <el-form-item>
        <el-date-picker
          v-model="bannerQueryJson.end"
          type="datetime"
          placeholder="选择截止时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          default-time="00:00:00"
        />
      </el-form-item>

      <el-button type="primary" icon="el-icon-search" @click="getList()">查询</el-button>
      <el-button type="default" @click="resetData()">清空</el-button>
    </el-form>

    
  <!-- 表格 -->
    <el-table
      :data="list"
      border
      fit
      highlight-current-row>

      <el-table-column
        label="序号"
        width="70"
        align="center">
        <template slot-scope="scope">
          {{ (current - 1) * pagesize + scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column prop="title" label="标题" width="80" />

      <el-table-column prop="linkUrl" label="链接地址" width="80"/>
       

      <el-table-column prop="imageUrl" label="图片地址" />

      <el-table-column prop="gmtCreate" label="添加时间" width="160"/>

      <el-table-column prop="sort" label="排序" width="60" />

      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <router-link :to="'/crmBanner/edit/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit">修改</el-button>
          </router-link>
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="removeDataById(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
<!-- 分页 -->
    <el-pagination
      :current-page="current"
      :page-size="pagesize"
      :total="total"
      style="padding: 30px 0; text-align: center;"
      layout="total, prev, pager, next, jumper"
      @current-change="getList"
    />

</div>
</template>

<script>
//引入调用teacher.js文件
import crmbanner from '@/api/edu/crmbanner' 
export default {
    //核心代码位置
    data(){
      return {
          list:null,       //查询之后接口返回集合
          current:1,       //当前页
          pagesize:3,     //每页记录数
          total:0,          //总记录数
          bannerQueryJson:{}  //条件查询封装
      }
    },
    created(){
       this.getList()
    },
    methods:{
      //条件分页查询的方法
        getList(current=1){
            this.current=current
            crmbanner.getCrmBannerList(this.current,this.pagesize,this.bannerQueryJson)
           .then(response =>{
               this.list=response.data.rows
               this.total=response.data.total
               console.log(response)
           })
           .catch(error =>{
               console.log(error)
           })
        },
        //清空的方法
         resetData() {
            //表单输入项数据清空
            this.bannerQueryJson = {}
            //查询所有讲师数据
            this.getList()
        },
        //删除数据的方法
        removeDataById(id){
           // debugger
           // console.log(memberId)
            this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
                return crmbanner.removeCrmBannerById(id)
          }).then(() => {
             this.getList()
             this.$message({
              type: 'success',
              message: '删除成功!'
               })
               }).catch((response) => { // 失败
            if (response === 'cancel') {
                this.$message({
                type: 'info',
                message: '已取消删除'
              })
                 } else {
                   this.$message({
                   type: 'error',
                      message: '删除失败'
                 })
               }
           })
        }
        
    }
}
</script>